package com.lyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyun.bo.GetBlackListBo;
import com.lyun.mapper.BlacklistMapper;
import com.lyun.pojo.Blacklist;
import com.lyun.service.BlacklistService;
import com.lyun.vo.BlacklistVO;
import com.lyun.vo.PageVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;

@DubboService
public class BlacklistServiceImpl extends ServiceImpl<BlacklistMapper, Blacklist> implements BlacklistService {

    @Resource
    private BlacklistMapper blacklistMapper;

    /**
     * 获取黑名单列表
     *
     * @return
     */
    @Override
    public PageVO<BlacklistVO> getPageList(GetBlackListBo bo) {
        Page<Blacklist> pageInfo = new Page<>(bo.getPage(), bo.getPageSize());

        LambdaQueryWrapper<Blacklist> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Blacklist::getSelfId, bo.getId());
        Page<Blacklist> blacklistPage = blacklistMapper.selectPage(pageInfo, queryWrapper);

        PageVO<Blacklist> vo = new PageVO<>(blacklistPage);
        PageVO<BlacklistVO> blacklistVO = new PageVO<>();

        BeanUtils.copyProperties(vo, blacklistVO);

        blacklistVO.setPage(bo.getPage());
        blacklistVO.setPageSize(bo.getPageSize());

        return blacklistVO;
    }

    @Override
    public boolean deleteById(long blacklistId) {
        return blacklistMapper.deleteById(blacklistId) > 0;
    }
}
